package com.video.netty.InChannelHandler;

import com.alibaba.fastjson.JSONObject;
import com.video.netty.commons.utils.MsgUtil;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * 执行方案的状态响应
 * {"id":"startSolutionTaskResponse", "response":"success", "account":"admin"}
 * {"id":"startSolutionTaskResponse", "response":"fail", "account":"admin"}
 */
@BaseChannelHandler.MsgHandler
public class WsStartSolutionTaskResponseChannelHandler extends BaseChannelHandler {
    @Override
    protected String msgId() {
        return "startSolutionTaskResponse";
    }

    @Override
    protected void msgHandler(JSONObject json) throws Exception {

        //获得响应结果状态
        String status = json.getString("response");
        //消息id
        String msgid = json.getString("msgid");

        //获取阻塞队列
        BlockingQueue blockQueue = MsgUtil.getBlockQueue(msgid);
        if (blockQueue != null){
            //将状态放入阻塞队列
            blockQueue.offer(status, 5, TimeUnit.SECONDS);
        }

    }
}
